let apply = require('./apply');//申请立案
let accept = require('./accept');//案件受理
let reject = require('./reject');//案件拒绝受理
let supplement = require('./supplement');//案件拒绝受理
let affinity = require('./affinity');//获取案件关联码
let caseFile = require('../component/caseFile');//读写案件信息

/**
 * 立案模块脚本
 * @param pupConfig 基础配置信息
 * @returns caseInfo 案件信息
 * {
 *  caseId: string,//案件ID
 *  secretaryId: string，//秘书账号
 *  chiefArbitratorId: string，//首席仲裁员账号
 *  affinityCode：string //案件关联码
 *  courtType:int //庭审方式，0是现场庭审，1是书面庭审，默认为0
 * }
 */
const start = async (pupConfig) => {
  //启动类型:0是案件受理，1是案件拒绝受理，2是案件补充材料并受理,-1是不启动脚本。默认为0。
  let {type = 0} = pupConfig.config.filing.start;
  if (type === -1) {
    return;
  }

  let caseInfo = await apply(pupConfig);//案件信息
  await caseFile.write(caseInfo);//保存案件信息

  if (type === 0) {
    await accept(pupConfig, caseInfo);
  } else if (type === 1) {
    await reject(pupConfig, caseInfo);
  } else if (type === 2) {
    await supplement(pupConfig, caseInfo);
    await accept(pupConfig, caseInfo);
  }

  return caseInfo;
}

module.exports = start;